package com.wanmait.employment.manageController;

import com.github.pagehelper.PageInfo;
import com.wanmait.employment.aop.LogInfo;
import com.wanmait.employment.entity.Industry;
import com.wanmait.employment.service.IndustryService;
import com.wanmait.employment.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("manage/Industry")
public class IndustryController {

    @Resource
    private IndustryService industryService;
    @GetMapping("list")
    public AjaxResult list(String title, Integer pageNum, Integer pageSize){
        PageInfo<Industry> industryPageInfo= industryService.selectList(title,pageNum,pageSize);
        return AjaxResult.success("",industryPageInfo);
    }
    @GetMapping("listAll")
    public AjaxResult listAll(){
        List<Industry> industryList= industryService.selectListAll();
        return AjaxResult.success("",industryList);
    }

    @PostMapping("update")
    public AjaxResult update(@RequestBody Industry industry){
        if(industry.getId()!=null){
            industryService.update(industry);
            return AjaxResult.success("");
        }
        Boolean b=industryService.insert(industry);
        if(b){
            return AjaxResult.success("");
        }
        return AjaxResult.error("该行业已存在！");
    }
    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        industryService.delete(id);
        return AjaxResult.success("");
    }
}
